#include<bits/stdc++.h>
using namespace std;
int T,n,m,L,V;
int d[500001],v[500001],a[500001],p[500001];
int num1[1001],num2[1001],smax[1001];
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    for(int i=1;i<=T;i++)
    {
        cin>>n>>m>>L>>V;
        for(int j=1;j<=n;j++)
        {
            cin>>d[j]>>v[j]>>a[j];
        }
        for(int j=1;j<=m;j++)
        {
            cin>>p[j];
        }
        for(int j=1;j<=n;j++)
        {
            if(v[j]>V)
            {
                if(d[j]<=p[m])
                {
                    num1[i]++;
                    smax[i]=max(smax[i],j);
                }
            }
        }
        for(int j=1;j<=m;j++)
        {
            if(smax[i]<=p[j])
            {
                num2[i]++;
            }
        }
    }
    for(int i=1;i<=T;i++)
    {
        cout<<num1[i]<<" "<<num2[i]-1<<endl;
    }
}
//cout<<endl<<"*"<<p[j];
/*
1
15 5 20 5
1 1 0
2 9 0
3 2 0
4 8 0
5 3 0
6 7 0
7 4 0
8 6 0
9 5 0
10 5 0
11 1 0
12 9 0
13 2 0
14 8 0
15 3 0
2 4 6 8 10
*/
